package com.mylove.textprogressbar;

import android.app.ActivityManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;

import java.util.List;

/**
 * @author myLove
 * @time 2017/12/29 13:10
 * @e-mail love@yanyi.red
 * @overview
 */

public abstract class BaseActivity extends AppCompatActivity {
    private String TAG = "";

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(setContentView());
        TAG = getActivityName();
        init();
    }

    protected abstract int setContentView();

    protected abstract void init();

    protected <T extends View> T $(int id) {
        return findViewById(id);
    }

    protected void startActivity(Class cla) {
        Intent intent = new Intent(this, cla);
        startActivity(intent);
    }

    protected void v(Object... objects) {
        for (Object object : objects) {
            Log.v(TAG, object.toString());
        }
    }

    protected void e(Object... objects) {
        for (Object object : objects) {
            Log.e(TAG, object.toString());
        }
    }

    protected void d(Object... objects) {
        for (Object object : objects) {
            Log.d(TAG, object.toString());
        }
    }

    protected void i(Object... objects) {
        for (Object object : objects) {
            Log.i(TAG, object.toString());
        }
    }

    protected String getActivityName() {
        ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
        List<ActivityManager.RunningTaskInfo> taskInfo = activityManager.getRunningTasks(1);
        ComponentName componentInfo = taskInfo.get(0).topActivity;
        return componentInfo.getPackageName();
    }
}
